//
//  User.m
//  Closer
//
//  Created by zhangkai on 16/3/10.
//  Copyright © 2016年 Closer_All. All rights reserved.
//

#import "User.h"

static User * _instance=nil;

@implementation User

//单例
+(instancetype)shareInstance{

    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance=[[User alloc]init];
    });
    return _instance;
}

+(instancetype)allocWithZone:(struct _NSZone *)zone{


    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
      
      _instance=[super allocWithZone:zone];
        
    });
    
    return _instance;
}
-(instancetype)init{

    __block User *temp=self;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        temp= [super init];
        if (temp!=nil) {
            
        }
    });
    self=temp;
    return self;
}


///登陆


-(BOOL)addFriendWith:(NSString*)friend_username{
    EMError *error=nil;
    BOOL isSuccess = [[EaseMob sharedInstance].chatManager addBuddy:friend_username message:@"我想加您为好友" error:&error];
    if (isSuccess && !error) {
        NSLog(@"添加成功");
        return YES;
    }else{
    NSLog(@"添加失败");
        return NO;
    }
}
///好友列表
-(NSArray*)getFriendsList{
    
    __block NSMutableArray *array=[[NSMutableArray alloc]init];
    
    [[EaseMob sharedInstance].chatManager asyncFetchBuddyListWithCompletion:^(NSArray *buddyList, EMError *error) {
        if (!error) {
            
            array= [NSMutableArray arrayWithArray:buddyList]  ;
            
        }
    } onQueue:nil];
    
    return array;
}
@end
